package reno.eureka.timecycle.entity;

public class CetusExplainMO {

    /**
     * 时间处理逻辑
     * author RenoSirp
     */
    public CetusExplainMO(CycleMO cycleMO) {
        long timeCurr = System.currentTimeMillis() / 1000;
        long timeTarg = Long.valueOf(cycleMO.getId());
        System.out.println("TimeCurr:"+timeCurr);
        System.out.println("TimeTarg:"+timeTarg);
        while (timeTarg <= timeCurr) {
            if (cycleMO.isDay()) {
                timeTarg += 3000;
            } else {
                timeTarg += 6000;
            }
            cycleMO.setDay(!cycleMO.isDay());
        }
        cycleMO.setId(String.valueOf(timeTarg));
        long timeResult = timeTarg - timeCurr;
        if (cycleMO.isDay()) {
            currval = "白天";
            nextval = "夜晚";
        } else {
            currval = "夜晚";
            nextval = "白天";
        }
        if (timeResult == 0) {
            timeString.append("正在切换");
        } else {
            int hour = (int) (timeResult / 3600);
            int min = (int) ((timeResult / 60) % 60);
            int sec = (int) (timeResult % 60);
            if (hour > 0) {
                timeString.append(" ").append(hour).append(" 小时");
            }
            if (min > 0) {
                timeString.append(" ").append(min).append(" 分钟");
            }
            timeString.append(" ").append(sec).append(" 秒");
        }
        PersistentCycleMO.getInstance().setCetusCycle(cycleMO);
    }

    private String currval;
    private String nextval;
    private StringBuffer timeString = new StringBuffer();

    public String getCurrval() {
        return currval;
    }

    public void setCurrval(String currval) {
        this.currval = currval;
    }

    public String getNextval() {
        return nextval;
    }

    public void setNextval(String nextval) {
        this.nextval = nextval;
    }

    public StringBuffer getTimeString() {
        return timeString;
    }

    public void setTimeString(StringBuffer timeString) {
        this.timeString = timeString;
    }
}
